package com.itheima.ydd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.ydd.entity.Menu;
import com.itheima.ydd.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author yan.zhou
 * @since 2022-02-22
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select t3.* from sys_role t1 " +
            "join sys_role_menu t2 " +
            "on t1.id = t2.role_id " +
            "join sys_menu t3 " +
            "on t2.menu_id = t3.id " +
            "where t3.pid = 0 " +
            "and t1.id = #{id}")
    List<Menu> selectParentList(String id);

    @Select("select t2.* from sys_role_menu t1 " +
            "join sys_menu t2 " +
            "on t1.menu_id = t2.id " +
            "where t2.pid = #{id} " +
            "and t1.role_id = #{roleId}")
    List<Menu> selectChildList(@Param("roleId") String roleId,@Param("id") Integer id);

}
